<%@ page contentType="text/html; charset=UTF-8" %>
<%@ page import="java.util.List" %>
<%@ page import="com.cinsea.settings.model.Globalsetting" %>
<%@ page import="com.cinsea.settings.service.GlobalsettingService" %>
<%@ page import="com.cinsea.common.Env" %>
<%@ page import="com.cinsea.htmlselect.service.OptionService" %>
<%@ page import="com.cinsea.htmlselect.model.Option" %>
<%@ page import="com.cinsea.workflow.service.WfdefineService" %>
<%@ page import="com.cinsea.workflow.model.Wfdefine" %>
<%@ page import="com.cinsea.security.service.UserService" %>
<%@ page import="com.alibaba.fastjson.JSON" %>
<%@ include file="/common/common.jsp" %>
<%
    response.setHeader("cache-control", "no-cache");
    response.setHeader("pragma", "no-cache");
    response.setHeader("expires", "Mon 1 Jan 1990 00:00:00 GMT");
    JdbcDao jdbcDao = Env.getBean("jdbcDao");
    List<Map> gzlList = new ArrayList<Map>();//工作令信息list
    List<Map> humanList = new ArrayList<Map>();//人信息list
    List<Map> gsList = new ArrayList<Map>();//工时List
    List<Map> ckgsList = new ArrayList<Map>();//参考工时List
    Map orderMap = new HashMap();

    String column = "";
    String orderJson = "";
    String budgetJson = "";
    String yearBudgetJson="";
    String totalExpendJson = "";
    String peopleExpendJson ="";
    //1.接收年、月参数
    String year = StringUtil.null2String(request.getParameter("year"));
    String month = StringUtil.null2String(request.getParameter("month"));
    String isRedirect = StringUtil.null2String(request.getParameter("isRedirect"));

    if(!year.equals("") && !month.equals("")){
        //2.查询数据，从视图和gongshi6表两数据源进行查询(技术中心)
        String sql = "select v.gzlid,v.userid,v.gs,t.reason,t.confirm from v_zbc_statistics v left join ut_zbc_gongshi6 t\n" +
                "on v.gzlid=t.gzlid and v.userid=t.userid where v.year=? and v.month=? and v.userid in(select id from cs_human " +
                "where orgid='8ad083891a32987e011a32ba07e0007b')";
        gsList = jdbcDao.queryForList(sql,new Object[]{year,month});
        Set gzlSet = new HashSet();
        Set humanSet = new HashSet();
        if(gsList.size()>0){

            for(Object obj:gsList){
                Map map = (Map)obj;
                gzlSet.add(map.get("gzlid"));
                humanSet.add(map.get("userid"));
            }
        }
        for(Object gzlid:gzlSet){
            String gzlsql = "select id,orderid,ordername from ut_workorderoffer where id=?";
            Map gzlInfo = jdbcDao.queryForMap(gzlsql,new Object[]{gzlid});
            gzlList.add(gzlInfo);
        }
        for(Object humanid:humanSet){
            String humansql = "select id,objname from cs_human where id = ?";
            Map humanInfo = jdbcDao.queryForMap(humansql,new Object[]{humanid});
            humanList.add(humanInfo);
        }

        for(Map human : humanList){
            int m = NumberUtil.getIntegerValue(month);
            if(m == 1){
                column = "gs1";
            }else if(m == 2){
                column = "gs2";
            }else if(m == 3){
                column = "gs3";
            }else if(m == 4){
                column = "gs4";
            }else if(m == 5){
                column = "gs5";
            }else if(m == 6){
                column = "gs6";
            }else if(m == 7){
                column = "gs7";
            }else if(m == 8){
                column = "gs8";
            }else if(m == 9){
                column = "gs9";
            }else if(m == 10){
                column = "gs10";
            }else if(m == 11){
                column = "gs11";
            }else if(m == 12){
                column = "gs12";
            }
            String yearsql = "select id from cs_option where objname=?";
            Map yearId = jdbcDao.queryForMap(yearsql,new Object[]{year});
            if(yearId != null){
                try {
                    String ckgssql = "select userid,"+column+" from ut_gongshi_user where year=? and userid=?";
                    Map info = jdbcDao.queryForMap(ckgssql,new Object[]{yearId.get("id"),human.get("id")});
//                    System.out.println("ckgssql:"+ckgssql);
                    ckgsList.add(info);
                } catch (Exception e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                }
            }
        }

        Map orderInfo = new HashMap();
        List<Map> orderList = new ArrayList<Map>();//参考信息中的前两行数据
        for(Map gzl : gzlList){
            String gzlSql = "select id,begindate,enddate,budget from ut_workorderoffer where processid=?";
            Map info = jdbcDao.queryForMap(gzlSql,new Object[]{gzl.get("id")});
            orderList.add(info);
        }
        orderInfo.put("orderlist",orderList);
        orderJson = JSON.toJSONString(orderInfo);
        //
        Map prjBudgetInfo = new HashMap();
        List<Map> prjBudgetList = new ArrayList<Map>();
        for(Map gzl : gzlList){
            try{
                String prjbudgetSql = "select prjid,sum(val) as totalVal from ut_prjbudget where prjid=? and  kemu in" +
                        "('8ad0828f24d86fbd01256ca350fc1df4'," +
                        "'8ad0828f24d86fbd01256ca2f5011de4'," +
                        "'8ad0828f24d86fbd01256ca2bc8c1dd4') group by prjid";
                Map prjbudgetMap = jdbcDao.queryForMap(prjbudgetSql,new Object[]{gzl.get("id")});
                prjBudgetList.add(prjbudgetMap);
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        prjBudgetInfo.put("prjBudgetList",prjBudgetList);
        budgetJson=JSON.toJSONString(prjBudgetInfo);
        //
//        Map yearBudget = new HashMap();
//        List<Map> yearBudgetList = new ArrayList<Map>();
//        for(Map gzl : gzlList){
//            try{
//                String yearBudgetSql = "select orderid,ndyfryfyys from ut_expensebudget where year=? and orderid=?";
//                Map info = jdbcDao.queryForMap(yearBudgetSql,new Object[]{year,gzl.get("id")});
//                yearBudgetList.add(info);
//            }catch(Exception e){
//                e.printStackTrace();
//            }
//        }
//        yearBudget.put("yearBudgetList",yearBudgetList);
//        yearBudgetJson= JSON.toJSONString(yearBudget);

        //
        Map totalExpend = new HashMap();
        List<Map> totalExpendList = new ArrayList<Map>();
        String years = year+"-"+month+"-30";
        for(Map gzl : gzlList){
            try{
                String totalExpendSql = "select requestid,sum(val) as totalval from ut_erpfee where requestid=? and '"+years+"'>lf " +
                        "group by requestid";
                Map totalExpendInfo = jdbcDao.queryForMap(totalExpendSql,new Object[]{gzl.get("id")});
                totalExpendList.add(totalExpendInfo);
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        totalExpend.put("totalExpendList",totalExpendList);
        totalExpendJson = JSON.toJSONString(totalExpend);
//        //
        Map peopleExpend = new HashMap();
        List<Map> peopleExpendList = new ArrayList<Map>();
        for(Map gzl : gzlList){
            try{
                String peopleExpendSql = "select requestid,sum(val) as totalval from ut_erpfee where requestid=? and '"+years+"'>lf " +
                        "and erpkm in('614.0000.530102.60326.000000.00000','614.0000.530102.60327.000000.00000'," +
                        "'614.0000.530102.60328.000000.00000') group by requestid";
                Map peopleExpendInfo = jdbcDao.queryForMap(peopleExpendSql,new Object[]{gzl.get("id")});
                peopleExpendList.add(peopleExpendInfo);
            }catch(Exception e){
                e.printStackTrace();
            }
        }
        peopleExpend.put("peopleExpendList",peopleExpendList);
        peopleExpendJson = JSON.toJSONString(peopleExpend);
    }
%>
<html>
<head>
    <%@ include file="/common/head.jsp" %>

</head>
<body onload="">
<div id="mainDiv">
    <div id="selectDiv" align="center" style="width: 100%; background-color: darkgray">
        <form action="/zbc/zbc_statistics.jsp" method="post" id="selectForm">
            <table id="timeTable" width="100%" border="0">
                <tr>
                    <td style="text-align: right; " width="250px"><span >年:</span></td>
                    <td>
                        <input type="text" id="year" name="year" onchange="check()" value="<%=year%>"/><!-- onchange="check()" -->
                    </td>
                    <td style="text-align: right;" onchange=""> 月: </td>
                    <td>
                        <%--<input type="text" id="month" name="month"/>--%>
                        <select id="month" name="month" style="width: 125px">
                            <% for(int i=1; i<=12; i++){%>
                                <option ><%=i%></option>
                            <% } %>
                        </select>
                    </td>
                </tr>
                <tr>
                    <td colspan="4">
                        <span style="float: right;margin-right: 100px">
                            <input type="button" value="导 出" style="width: 80px" onclick="_export()"/>
                        </span>
                        <span style="float: right;margin-right: 75px">
                            <input type="button" value="提 交" style="width: 80px" onclick="reportSubmit();"/>
                        </span>
                        <span style="float: right;margin-right: 100px">
                            <input type="button" value="计 算" style="width: 80px" onclick="calculate()"/>
                        </span>
                        <span style="float: right;margin-right: 100px">
                            <input type="button" value="查 询" style="width: 80px" onclick="reportSelect()"/>
                        </span>
                    </td>
                </tr>
            </table>
        </form>
    </div>

    <div id="reportDiv"  align="center" style="width: 100%;height: 100%;">
        <form action="" id="submitForm" method="post">
            <table border=1 id="reportTable" style="text-align: center">
                <caption>
                    <p style="text-align: center;font-size: 30px"><%=year%> 年<%=month%> 月科技项目人工费用汇总表(技术中心人员)</p>
                </caption>
                <tr>
                    <td rowspan="2" style="text-align: left">
                        <input type="image" src="/zbc/firstCol.jpg"/>
                    </td>
                    <% int x=1,y=1,allRow=0,gshjRow=0;
                        for(Map map : gzlList){ %>
                    <td colspan="3">
                        <%=map.get("orderid")%>
                        <input type="hidden" id="<%="orderid-"+y%>" name="<%="orderid-"+y%>" value="<%=map.get("id")%>"/>
                        <input type="hidden" id="col" name="col" value="<%=y%>" />

                    </td>
                    <% y++; } int c=y-1;%>
                    <td rowspan="2" style="width: 85px" align="center">
                        <b>实际参考工时</b>
                    </td>
                    <td rowspan="2" style="width: 85px" align="center">
                        <b>有效工时小计</b>
                    </td>
                    <td rowspan="2" style="width: 85px" align="center">
                        <b>无效工时小计</b>
                    </td>
                </tr>

                <tr>
                    <%
                        y=1;
                        for(Map map : gzlList){ %>
                    <td>
                        <input type="checkbox" id="<%="headconfirm-"+y%>" name="<%="headconfirm-"+y%>" onclick="allSelect(this)"/><!--  全选  -->
                    </td>
                    <td colspan="2">
                        <%=map.get("ordername")%>
                    </td>
                    <% y++; } %>
                </tr>
                <%
                    y=1;
                    for(Map humanMap : humanList){
                %>
                <tr>
                    <td>
                        <%=humanMap.get("objname")%>
                        <input type="hidden" id="<%="humanid-"+x%>" name="<%="humanid-"+x%>" value="<%=humanMap.get("id")%>"/>
                    </td>
                    <% for(Map gzlMap : gzlList){
                        String reason="";
                        int confirm=0;
                        String gs="";
                        for(Map gsMap : gsList){
                            if(gsMap.get("userid").equals(humanMap.get("id")) && gsMap.get("gzlid").equals(gzlMap.get("id"))){
                                reason=StringUtil.null2String(gsMap.get("reason"));
                                confirm=NumberUtil.getIntegerValue(gsMap.get("confirm"),0);
                                gs=StringUtil.null2String(gsMap.get("gs"));
                                break;
                            }
                        }
                    %>
                    <td>
                        <input type="checkbox" id="<%="confirm-"+x+"-"+y%>" name="<%="confirm-"+x+"-"+y%>" <%if(confirm==1){%>checked<%}%> value="1"/>
                    </td>
                    <td>
                        <input type="text" id="<%="reason-"+x+"-"+y%>" name="<%="reason-"+x+"-"+y%>" value="<%=reason%>">
                    </td>
                    <td>
                        <span id="<%="gs-"+x+"-"+y%>" name="<%="gs-"+x+"-"+y%>"><%=gs%></span>
                    </td>
                    <% y++; } %>
                    <%
                        String ckgsValue = "";
                        for(Map ckgsMap : ckgsList){
                            if(ckgsMap.get("userid").equals(humanMap.get("id"))){
                                ckgsValue = StringUtil.null2String(ckgsMap.get(column));
                                break;
                            }
                        }
                    %>
                    <!-- readonly="readonly" -->
                    <td style="width: 70px"><input type="text"  id="<%="reference-"+x%>" name="<%="reference-"+x%>" value="<%=ckgsValue%>" readonly="readonly"/></td>
                    <td style="width: 70px"><input type="text" readonly="readonly"  id="<%="valid-"+x%>" name="<%="valid-"+x%>" value="0"/></td>
                    <td style="width: 70px"><input type="text" readonly="readonly"  id="<%="invalid-"+x%>" name="<%="invalid-"+x%>" value="0"/></td>
                </tr>
                <% x++; y=1;} int r=x-1;%>
                <tr>
                <td style="text-align: left"><b>当月研发人员工时合计:</b></td>
                    <%  int rr = ++r;
                        gshjRow=rr;
                        for(int i=1; i<=c; i++){  %>
                        <td colspan="3"><input  type="text" readonly="readonly" id="<%="gshj-"+r+"-"+i%>" name="<%="gshj-"+r+"-"+i%>"/> </td>
                <% } %>
                <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                <td style="width: 70px"><input type="text" disabled="true"  id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
            </tr>

                <tr>
                    <td style="text-align: left"><b>当月研发人员费用合计：</b></td>
                        <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                            <td colspan="3" ><input type="text" readonly="readonly" id="<%="fyhj-"+r+"-"+i%>" name="<%="fyhj-"+r+"-"+i%>"/> </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                <td style="text-align: left"><b>参考信息</b></td>
                <%
                    ++r;
                    for(int i=1; i<=c; i++){  %>
                    <td colspan="3" id="<%="white-"+r+"-"+i%>" name="<%="white-"+r+"-"+i%>"><input type="hidden" disabled="true"/></td>
                <% } %>
                <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="h-"+r%>"/></td>
                <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"></td>
                <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
            </tr>

                <tr>
                    <td style="text-align: left">项目起止时间</td>
                    <%
                        int row = ++r;
                        for(int i=1; i<=c; i++){  %>
                            <td colspan="3" >
                                <input type="text" readonly="readonly" id="<%="begin-end-"+r+"-"+i%>" name="<%="begin-end-"+r+"-"+i%>"/>
                            </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left">项目总预算</td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                    <td colspan="3" >
                        <input type="text" readonly="readonly" id="<%="zys-"+r+"-"+i%>" name="<%="zys-"+r+"-"+i%>" value="0"/>
                    </td>
                    <% } %>
                    <td style="width: 70px"><input disabled="true" type="text" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input disabled="true" type="text" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input disabled="true" type="text" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left">研发人员费用预算</td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                    <td colspan="3" >
                        <input type="text" readonly="readonly" id="<%="yfryfyys-"+r+"-"+i%>" name="<%="yfryfyys-"+r+"-"+i%>" value="0"/>
                    </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left"><%=year+"年研发人员费用预算"%></td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                    <td colspan="3" >
                        <input type="text" readonly="readonly" id="<%="year-yfryfyys-"+r+"-"+i%>" name="<%="year-yfryfyys-"+r+"-"+i%>" value="0"/>
                    </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left">累计总支出</td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                        <td colspan="3" >
                            <input type="text" readonly="readonly" id="<%="ljzzc-"+r+"-"+i%>" name="<%="ljzzc-"+r+"-"+i%>" value="0"/>
                        </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left">累计研发人员费用支出</td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                        <td colspan="3" >
                            <input type="text" readonly="readonly" id="<%="ljyfryfyzc-"+r+"-"+i%>" name="<%="ljyfryfyzc-"+r+"-"+i%>" value="0"/>
                        </td>
                    <% } %>
                    <td style="width: 70px"><input id="<%="reference-"+r%>" name="<%="reference-"+r%>" type="text" disabled="true"/></td>
                    <td style="width: 70px"><input id="<%="valid-"+r%>" name="<%="valid-"+r%>" type="text" disabled="true"/></td>
                    <td style="width: 70px"><input id="<%="invalid-"+r%>" name="<%="invalid-"+r%>" type="text" disabled="true"/></td>
                </tr>

                <tr>
                    <td style="text-align: left">总预算与累计总支出差值</td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                    <td colspan="3" >
                        <input type="text" readonly="readonly" id="<%="cz1-"+r+"-"+i%>" name="<%="cz1-"+r+"-"+i%>" value="0"/>
                    </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left">预算与累计研发人员费用累计支出差值</td>
                    <%
                        ++r;
                        for(int i=1; i<=c; i++){  %>
                    <td colspan="3">
                        <input type="text" readonly="readonly" id="<%="cz2-"+r+"-"+i%>" name="<%="cz2-"+r+"-"+i%>" value="0"/>
                    </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true"  id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true"  id="<%="valid-"+r%>" name="<%="valid-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true"  id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td style="text-align: left"><%="研发人员费用预算与加上"+month+"月的研发人员费用后的差值"%></td>
                    <%
                        allRow = ++r;
                        for(int i=1; i<=c; i++){  %>
                    <td colspan="3" >
                        <input type="text" readonly="readonly" id="<%="cz3-"+r+"-"+i%>" name="<%="cz3-"+r+"-"+i%>" value="0"/>
                    </td>
                    <% } %>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="reference-"+r%>" name="<%="reference-"+r%>"/></td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="valid-"+r%>" name="<%="valid-"+r%>" /> </td>
                    <td style="width: 70px"><input type="text" disabled="true" id="<%="invalid-"+r%>" name="<%="invalid-"+r%>"/></td>
                </tr>

                <tr>
                    <td colspan="<%=4+c%>">
                        <input type="hidden" id="x" name="x" value="<%=x%>"/>
                        <input type="hidden" id="y" name="y" value="<%=c%>"/>
                        <input type="hidden" id="selectYear" name="selectYear" value="<%=year%>"/>
                        <input type="hidden" id="selectMonth" name="selectMonth" value="<%=month%>"/>
                        <input type="hidden" id="gshjRow" name="gshjRow" value="<%=gshjRow%>"/>
                        <input type="hidden" id="maxRow" name="maxRow" value="<%=allRow%>"/>
                    </td>
                </tr>
            </table>
        </form>
    </div>
</div>
<script type="text/javascript">
    $(function(){
        calculate();
        getCkxx();
    });
    function getCkxx(){
        var row = <%=row%>;
        var y = <%=c%>;//列数，即一行有多少个工作令
        var row_zys= 0,row_zzc= 0,row_yfryfyys= 0,row_yfryfyzc= 0;
        var x=<%=rr%>;
        var row_dyyfryfy = x+1;
        var orders = [];
        var peopleBudget = [];
        var yearBudget = [];
        var totalExpend = [];
        var peopleExpend = [];
        var orderJson = <%=orderJson%>;
        var peopleBudgetJson = <%=budgetJson%>;
        <%--var yearBudgetJson = <%=yearBudgetJson%>;--%>
        var totalExpendJson = <%=totalExpendJson%>;
        var peopleExpendJson = <%=peopleExpendJson%>;
        orders = orderJson.orderlist;
        peopleBudget = peopleBudgetJson.prjBudgetList;
//        yearBudget = yearBudgetJson.yearBudgetList;
        totalExpend = totalExpendJson.totalExpendList;
        peopleExpend = peopleExpendJson.peopleExpendList;

        for(var i=1; i<=y; i++){
            var orderid = $("#orderid-"+i).val();
            for(var j=0; j<orders.length; j++){
//                alert("orderid: "+orderid +"ordersID:"+orders[j].ID);
                if(orderid==orders[j].ID){
                    var begin = orders[j].BEGINDATE;
                    if(begin==null || begin==""){
                        begin = "";
                    }else{
                        begin = begin.substring(0,7);
                    }
                    var end = orders[j].ENDDATE;
                    if(begin==null || begin==""){
                        end = "";
                    }else{
                        end = end.substring(0,7);
                    }
                    if(begin=="" && end==""){
                        $("#begin-end-"+row+"-"+i).attr("value","");
                    }else{
                        $("#begin-end-"+row+"-"+i).attr("value",begin+"——"+end);
                    }
                    var budget = orders[j].BUDGET;
                    if(budget=="" || budget==null){
                        budget=0;
                    }
                    row_zys=row+1;
                    $("#zys-"+row_zys+"-"+i).attr("value",budget);
                }
            }

            for(var t=0; t<peopleBudget.length; t++){
                if(orderid==peopleBudget[t].PRJID){
//                    alert(peopleBudget[t].TOTALVAL);
                    var totalVal = peopleBudget[t].TOTALVAL;
                    if(totalVal=="" || totalVal==null){
                        totalVal=0;
                    }
                    row_yfryfyys=row+2;
                    $("#yfryfyys-"+row_yfryfyys+"-"+i).attr("value",totalVal);
                }
            }
//
//            for(var m=0; m<yearBudget.length; m++){
//                if(orderid==yearBudget[m].ORDERID){
//                    var value = yearBudget[m].NDYFRYFYYS;//ndyfryfyys
//                    if(value=="" || value==null){
//                        value=0;
//                    }
//                    $("#year-yfryfyys-"+(row+3)+"-"+i).attr("value",value);
//                }
//            }
//
            for(var n=0; n<totalExpend.length; n++){
                if(orderid == totalExpend[n].REQUESTID){
                    var value = totalExpend[n].TOTALVAL;
//                    alert(value);
                    if(value=="" || value==null){
                        value=0;
                    }
                    row_zzc=row+4;
                    $("#ljzzc-"+row_zzc+"-"+i).attr("value",value);
                }
            }
//
            for(var g=0; g<peopleExpend.length; g++){
                if(orderid == peopleExpend[g].REQUESTID){
                    var value = peopleExpend[g].TOTALVAL;
                    if(value=="" || value==null){
                        value=0;
                    }
                    row_yfryfyzc=row+5;
                    $("#ljyfryfyzc-"+row_yfryfyzc+"-"+i).attr("value",value);
                }
            }
        }
        getSubtractValue(row_zys,row_zzc,row_yfryfyys,row_yfryfyzc,row_dyyfryfy);
    }

    function getSubtractValue(){
        var y = <%=c%>;
        var row_zys= arguments[0];
        var row_zzc= arguments[1];
        var row_yfryfyys= arguments[2];
        var row_yfryfyzc= arguments[3];
        var row_dyyfryfy= arguments[4];
        for(var i=1; i<=y; i++){
            var zys = Number($("#zys-"+row_zys+"-"+i).val());//总预算
            var yfryfyys = Number($("#yfryfyys-"+row_yfryfyys+"-"+i).val());//研发人员费用预算
            var ljzzc = Number($("#ljzzc-"+row_zzc+"-"+i).val());
            var yfryfyzc = Number($("#ljyfryfyzc-"+row_yfryfyzc+"-"+i).val());
            var dyyfryfy = Number($("#fyhj-"+row_dyyfryfy+"-"+i).val());

            var row1_val = zys - ljzzc;
            var row2_val = yfryfyys - yfryfyzc;
            var row3_val = yfryfyys - yfryfyzc-dyyfryfy;

            $("#cz1-"+(row_yfryfyzc+1)+"-"+i).attr("value",row1_val);
            $("#cz2-"+(row_yfryfyzc+2)+"-"+i).attr("value",row2_val);
            $("#cz3-"+(row_yfryfyzc+3)+"-"+i).attr("value",row3_val);
        }
    }
</script>
</body>

</html>
<script type="text/javascript">

    //查询按钮点击事件
    function reportSelect(){
        //1.检查year、month两个文本框的值是否为空，为空则return false;
        var year = $("#year").val();
        var month = $("#month").val();
        if(year==""||year==null || month==""||month==null){
            alert("请输入年和月，再进行查询......");
            return ;
        }
        $("#selectForm").submit();
    }

    //全选
    function allSelect(){
        var objname = arguments[0].name;
        var y=0;
        if(objname.length>13){
            y = objname.substr(objname.length-2,objname.length);
        }else{
            y = objname.substr(objname.length-1,objname.length);//存在bug，如果列数为两位数，则不正确了
        }
        var x = <%=x%>-1;
        if(arguments[0].checked){
            for(var i=1; i<=x; i++){
                var colId = "confirm-"+i+"-"+y;
                $("#"+colId).attr('checked',true);
            }
        }else{
            for(var i=1; i<=x; i++){
                var colId = "confirm-"+i+"-"+y;
                $("#"+colId).attr('checked',false);
            }
        }
    }

    /**
     *计算
     */
    function calculate(){
        var x = <%=rr%>;//行数，即人数
        var y = <%=c%>;//列数，即一行有多少个工作令
//        alert("x:"+x+"  y："+y);
        if(x>0 && y>0){
            //横向
            for(var r=1; r<x; r++){
                var sum=0;              //有效工时
                for(var c=1; c<=y ; c++){
                    var temp = "confirm-"+r+"-"+c;
                    var confirm = $("#"+temp);
                    if(confirm[0].checked==true){
                        temp = temp.replace("confirm","gs");
                        var value = parseInt($("#"+temp).html());
                        if(value==""){
                            value =0;
                        }
                        sum=sum+value;
                    }
                }
                $("#valid-"+r).attr("value",sum);
                var ckgs = Number($("#reference-"+r).attr("value"));
                if(ckgs==""){
                    ckgs=0;
                }
                var wxgs = ckgs - sum;
                $("#invalid-"+r).attr("value",wxgs);
            }
            //纵向
            //当月研发人员费用合计
            var gzl = [];
            $.ajax({
                url:"/ext/com.cinsea.zbc.ext.ZbcAction?action=allCost&orgType=technology&year="+'<%=year%>'+"&month="+'<%=month%>',
                type:"post",
                async:false,
                success:function(result){
                    var val = Ext.decode(result);
                    gzl = val.gzllist;
                }
            });

            for(var c=1; c<=y; c++){
                var sum_gs =0;//工时
                var sum_fy=0;//费用
                for(var r=1; r<x; r++){
                    var temp = "confirm-"+r+"-"+c;
                    var confirm = $("#"+temp);
                    if(confirm[0].checked==true){
                        temp = temp.replace("confirm","gs");
                        var value = parseInt($("#"+temp).html());
                        if(value==""){
                            value =0;
                        }
                        sum_gs = sum_gs+value;

                        var humanid = $("#humanid-"+r).val();
                        for(var k=0; k<gzl.length; k++){
                            if(humanid==gzl[k].YGBH){
                                if(gzl[k].DWXSGZL>0){
                                    var value_fy =Number(gzl[k].DWXSGZL)*value;
                                    sum_fy = sum_fy+value_fy;
                                }
                            }
                        }
                    }
                }
                $("#gshj-"+x+"-"+c).attr("value",sum_gs);
                $("#fyhj-"+(x+1)+"-"+c).attr("value",sum_fy);
            }
        }
    }

    function _export(){
        $("#submitForm").attr("action","/ext/com.cinsea.zbc.ext.ZbcAction?action=export&orgType=technology");
        $("#submitForm").submit();
    }

    //提交按钮点击事件
    function reportSubmit(){
        $("#submitForm").attr("action","/ext/com.cinsea.zbc.ext.ZbcAction?action=insert&orgType=technology");
        $("#submitForm").submit();
    }

    //文本框的值发生改变时事件
    function check(){
        //通过正则表达式检查输入数据是否是数字，及格式是否正确
        var value = $("#year").val();
        var patrn = "2[0-9][0-9][0-9]$";
        var regExp = new RegExp(patrn);
        var flag = regExp.exec(value);
        if(!flag){
            alert("请输入正确的年份.....如：yyyy");
        }
    }

</script>
